module EventEditor
  module Route
    class SetSpeedDialog
     SPEED_MODEL = [['1:Slowest', 0], ['2:Slower', 1], ['3:Normal', 2], ['4:Faster', 3], ['5:Fastest', 4]]
     SPEED_TABLE = {
       0 => '1:Slowest',
       1 => '2:Slower',
       2 => '3:Normal',
       3 => '4:Faster',
       4 => '5:Fastest'
     }
     def self.show(base, &func)
       dialog = Gtk::Dialog.new("Move Wait",
               base,
               Gtk::Dialog::MODAL |
               Gtk::Dialog::DESTROY_WITH_PARENT,
               ["OK", Gtk::Dialog::RESPONSE_OK],
               ["Cancel", Gtk::Dialog::RESPONSE_CANCEL]
               )

        hbox = Gtk::HBox.new
        hbox.set_border_width(5)
        hbox.add(@speed_combobox = ::Gadgets::Combobox.new(SPEED_MODEL, [String, Integer]))
        hbox.add(Gtk::Label.new('frames'))
        dialog.vbox.add(hbox)
        dialog.vbox.show_all

        # run
        dialog.run do |response|
          if response == Gtk::Dialog::RESPONSE_OK
            func.call(@speed_combobox.selected_data)
          else
            func.call(:cancel)
          end
          dialog.destroy
        end
      end
      
      def self.command_to_s(args)
        return "Speed : #{SPEED_TABLE[args[1]]}"
      end
    end
  end
end